package daam.main;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FruitHunter extends Activity {
	/** Called when the activity is first created. */

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button start_button = (Button)findViewById(R.id.start_game);
		Button highscores_button = (Button)findViewById(R.id.highscores);
		Button settings_button = (Button)findViewById(R.id.settings);
		Button help_button = (Button)findViewById(R.id.howToPlay);


		start_button.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				newGame();

			}    	
		});

		highscores_button.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				highScores();
			}    	
		});

		settings_button.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {

				openMenu();
			}    	
		});

		help_button.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {

				howToPlay();

			}    	
		});

	}


	protected void howToPlay() {
		startActivity(new Intent(this, HowToPlay.class));

	}


	protected void highScores() {
		startActivity(new Intent(this, Highscores.class));		
	}


	protected void openMenu() {

		startActivity(new Intent(this, Settings.class));

	}


	protected void onDestroy() {
		super.onDestroy();

	}


	protected void onStop() {
		super.onStop();    
	}

	protected void onPause() {
		super.onStop();    
	}


	protected void newGame() {

		Intent i = new Intent(this,Game.class);
		startActivity(i);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event)  {

		if (keyCode == KeyEvent.KEYCODE_BACK  && event.getRepeatCount() == 0) {

			confirmarSaida();
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}


	private void confirmarSaida() {

		AlertDialog.Builder alert = new AlertDialog.Builder(this);
		alert.setTitle("Fruit Hunter");
		alert.setMessage("Tem a certeza que pretende sair?");

		alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				finish();
			}
		});

		alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				dialog.cancel();
			}
		});

		alert.show();

	}

}